<template>
    <view class="content">
		<page-head :title="i18n.main.present"></page-head>
		<image src="../../static/tabbar/return.png" mode="" class="page-return" @tap="back"></image>
		
		<view class="center">
			<view class="verified">
				<view class="reminder">{{i18n.integral.present}}</view>
				
				<view class="current">
					{{i18n.integral.current}}:
					<text>{{integral}}</text>
				</view>
				
				<view class="form">
					<view class="form-input">
						<m-input class="input" type="text" v-model="number" :placeholder="i18n.integral.number" maxlength="20"></m-input>
						
						<m-input class="input" type="text" v-model="account" :placeholder="i18n.integral.account" maxlength="20"></m-input>
						
						<m-input class="input" type="password" displayable v-model="pass2" :placeholder="i18n.integral.pass" maxlength="6"></m-input>
					</view>
				</view>
				
				<view class="form1">
					<button class="btn-submit" @tap="transfer">{{i18n.integral.transfer}}</button>
				</view>
			</view>
		</view>
		
		<image :src="back_img" mode="" class="back_img" :style="height"></image>
    </view>
</template>

<script>
	import service from '../../service.js';
	import mInput from '../../components/m-input.vue';
	import pageHead from '../../components/page-head.vue';
	export default {
		computed: {
			i18n () {
				return this.$t('index');
			}
		},
		components: {
			pageHead,
			mInput
        },
		data() {
			return {
				back_img:uni.getStorageSync('page'),
				height:uni.getStorageSync('height'),
				user:uni.getStorageSync('user'),
				integral:0,
				number:'',
				account:'',
				pass2:'',
			};
		},
		onShow:function(){
			uni.setNavigationBarTitle({
				title: this.i18n.main.present
			});
			this.integral = this.user.credit1;
		},
		methods:{
			back(){
				uni.switchTab({
					url: '/pages/main/user'
				})
			},
			transfer(){
				self = this;
				if(self.number == '' || self.number < 1){
					uni.showToast({
						icon: 'none',
						title: self.i18n.integral.number2
					});
					return;
				}
				var num = Math.ceil(self.integral) - Math.ceil(self.number);
				if(num < 0){
					uni.showToast({
						icon: 'none',
						title: self.i18n.integral.number3
					});
					return;
				}
				if(!(/^1[3-9][0-9]\d{8,11}$/.test(self.account))){
					uni.showToast({
						icon: 'none',
						title: self.i18n.integral.account2
					});
					return;
				}
				if(self.pass2 != '' && self.pass2.length != 6){
					uni.showToast({
						icon: 'none',
						title: self.i18n.integral.pass2
					});
					return;
				}
				service.upload(this, service.api.integral.transfer, {
					"credit":self.number,
					"account":self.account,
					"change_pwd":self.pass2
				}, '', '', function(_self, res) {
					uni.showToast({
						icon: 'none',
						title: res.info
					});
					if(res.code == 1){
						setTimeout(function(){
							uni.navigateBack({
								delta: 1
							})
						}, 1000);
					}else{
						self.status = 1;
					}
				});
			}
		}
    }
</script>

<style lang="scss">
	.content{
		padding: 0;
		background: #F2F2F2;
	}
	.center{
		z-index: 30;
		width: calc(100% - 60upx);
		margin: 0 30upx;
	}
	.verified{
		padding: 40upx 0;
		border-radius: 20upx;
		margin: 30upx 0 60upx;
		background: rgba(255,255,255,.7);
	}
	.current{
		color: #929292;
		font-size: 32upx;
		line-height: 60upx;
		margin: 30upx 60upx 0;
	}
	.current text{
		color: #00B26A;
		font-size: 36upx;
		line-height: 60upx;
	}
	.reminder{
		color: red;
		margin: 0 40upx;
		padding: 10upx 0;
		font-size: 26upx;
		text-align: center;
		line-height: 30upx;
		background: #ffe9e9;
	}
	.form{
		width: 100%;
		height: 320upx;
		margin-top: 40upx;
		border-top: 2upx solid #BBBBBB;
	}
	.form-input{
		height: 100upx;
		margin: 30upx 60upx 0;
	}
	.form-input .input{
		height: 60upx;
		margin: 0 0 20upx;
		border-radius: 20upx;
		padding: 10upx 20upx;
		width: calc(100% - 40upx);
		background: rgba(250,49,161,.2);
	}
	.btn-submit{
		height: 80upx;
		line-height: 80upx;
		margin: 30upx 20% 0;
	}
	.back_img{
		margin: 0;
		height: 100%;
	}
</style>